package client_commands

import scala.actors.Actor
import scala.actors.Actor._
import scala.actors.remote.Node
import scala.actors.remote.RemoteActor
import scala.actors.remote.RemoteActor._
import executors.NewFolderExecutor
import objects.File1

/**
 * Listens to updates about folder that were created in a client's dropbox.<br>
 * Works as a remote actor that listens to messages on a given port.<br>
 * @param - port to listen on.<br>
 * @param - executor : Actor
 */
class NewFolderActor(port: Int, executor : Actor) extends Actor {

  /**
   * The acting method of the actor.<br>
   * Receives messages about folders that were created in a client's dropbox and then sends <br>
   * the information forwards to be processed against the data-base and against other clients. 
   */
  def act() {
    alive(port)
    register('NewFolder, self)

    loop {
      react {
        case (uid : Long, cid : Long, name : String, parent : Long) =>
          {
            val receivedFolder = new File1(uid, cid, name, parent)
            println("processing new folder "+name+" parent: "+parent)
            var folderID = (executor !? receivedFolder)
            
            sender ! folderID
          }
        case "Quit" => {
          println("NewFolderActor stopped")
          executor ! "Quit"
          exit()
        }
        case _ =>
          println("NewFolderActor received unknown message")
      }
    }
  }

}

